﻿using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using SpectrumAnalyser.Common.ServiceHeaders;
using SpectrumAnalyser.Services.Common.Inspectors;

namespace SpectrumAnalyser.Services.Common.Bevaviors
{
    public class InstanceNameEndpointBehavior : IEndpointBehavior
    {
        private readonly InstanceNameHeader _instanceName;

        public InstanceNameEndpointBehavior(InstanceNameHeader instanceName)
        {
            this._instanceName = instanceName;
        }

        public void Validate(ServiceEndpoint endpoint)
        {
        }

        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            throw new NotSupportedException();
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.MessageInspectors.Add(new InstanceNameClientMessageInspector(this._instanceName));
        }
    }
}